package com.cool.commonredis;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Random;

/**
 * @Author ifredomvip@gmail.com
 * @Date 2022/7/25 16:14
 * @Version 1.0.0
 * @Description
 **/
@WebServlet
public class DoGetServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String userId = new Random().nextInt(5000) + "";

        String prodId = req.getParameter("prodid");

//        Boolean killProd = CommonRedisApplication.killProd(userId, prodId);

        // 使用lua脚本操作
        Boolean killProd = CommonRedisApplication.doSecKill(userId, prodId);

        resp.getWriter().println(killProd);
    }
}
